package DbfEdit;

import javax.swing.* ;
import javax.swing.table.* ;
import javax.swing.event.* ;
import java.awt.* ;
import java.util.* ;
import java.io.* ;

/*
 * TableModel f&uuml;r JTable
 */
public class DbfModel extends AbstractTableModel implements TableModel
{
   /**
    * Klasse f&uuml;r die Datenbank-Datei
    */
   Dbf dbf ;

   /**
    * Konstruktor
    */
   public DbfModel()
      throws RuntimeException
   {
      try
      {
         dbf = new Dbf( "C:\\Enkhee\\zugang.dbf" ) ;
      }
      catch ( Exception e )
      {
         System.out.println( "Datenbank konnte nicht geoeffnet werden " + e ) ;
         throw new RuntimeException( "Datenbank konnte nicht geoeffnet werden " + e ) ;
      }
      System.out.println( "Datenbank geoeffnet" ) ;
   } // end method DbfModel

   public int getColumnCount()
   {
      return dbf.getFieldCount() ;
   } // end method getColumnCount

   public int getRowCount()
   {
      return dbf.getRecCount() ;
   } // end method getRowCount

   public String getColumnName( int row )
   {
      return dbf.getFeldName( row ) ;
   } // end method getColumnName

   public Object getValueAt( int row , int col )
   {
      try
      {
         dbf.goTo( row + 1 ) ;
         if ( dbf.isMemoFeld( col ) )
         {
            return HeinerUtil.pad( dbf.getString( col ) , 100 ) ;
         }
         else
         {
            return dbf.getString( col ) ;
         }
      }
      catch ( IOException ioe ) {}
      return "" ;
   } // end method getValueAt

   public boolean isCellEditable( int row , int col )
   {
      return false ;
   } // end method isCellEditable

   public void setValueAt( Object oValue , int row , int column )
   {
      fireTableChanged( new TableModelEvent( this , row , row , column ) ) ;
   } // end method setValueAt
} // end class DbfModel
